<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="author" content="wangbo">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
    </div>

    <script type="text/javascript" src="../js/react.development.js">    </script>
    <script type="text/javascript" src="../js/react-dom.development.js">    </script>
    <script type="text/javascript" src="../js/prop-types.js">    </script>
    <script type="text/javascript" src="../js/babel.min.js">    </script>
    <script type="text/babel">
        class Button extends React.Component {
            constructor(props) {
                super(props);
                this.state = { data: 0 };
                this.setNewNumber = this.setNewNumber.bind(this);
            }

            setNewNumber() {
                this.setState({ data: this.state.data + 1 })
            }
            /*  1 因为componentWillMount是在render之前执行，所以在这个方法中setState不会发生重新渲染(re-render);
            2 这是服务端渲染(server render)中唯一调用的钩子(hook);
            3 通常情况下，推荐用constructor()方法代替;。因此项目中很少使用。 */
            componentWillMount() {
                console.log('Component 将要挂载,在reader之前')
                this.setState({ data: this.state.data + 1 })
            }
            render() {
                return (
                    <div>
                        <button onClick={this.setNewNumber}>声明周期 {this.state.data}</button>
                    </div>
                );
            }
        }


        ReactDOM.render(
            <div>
                <Button />
            </div>,
            document.getElementById('app')
        );
    </script>
</body>

</html>